﻿function secondMethod(){
	alert("Hello World in script file.");
} 

function getSquare(){
	var str=document.getElementById("txtData").value;
	if(isNaN(str))
		alert("请输入数值");
	else{
		var data=parseFloat(str);
		var result=data*data;
		alert(result);
	}
}

function guessNumber(){
	var result=10;
	var str=document.getElementById("txtNumber").value;
	
	if(isNaN(str))
		alert("请输入数值");
	else{
		var data=parseFloat(str);
		var info=data>result ? "大了" : "小了";
		info=data==result ? "猜对了" : info;
		alert(info);
	}
}

function getFac(){
	var result=1;
	for(var i=1;i<=10;i++){
		result*=i;
	}
	alert("10的阶乘为:"+result);
}


function searchStringAndReplace(){
	var str=document.getElementById("txtString").value;
	var index=str.indexOf("js",0);
	while(index>-1){
		str=str.replace("js","*");
		index=str.indexOf("js",index+1);
	}
	document.getElementById("txtString").value=str;
}


function stringByRegex(){
	var str=document.getElementById("txtString").value;
	var result=str.match(/js/gi);
	
	document.getElementById("txtString").value=str.replace(/js/gi,"*");
	alert("共替换了"+result.length+"处。");
}



//数组操作
function operateArray(t){
	var array=document.getElementById("txtNumbers").value.split(",");
	
	switch(t){
	case 1:
		array.reverse();
		break;
	case 2:
		array.sort();
		break;
	case 3:
		array.sort(sortFunc);
		break;
	}
	
	alert(array.toString());
}

//自定义排序
function sortFunc(a,b){
	return a-b;
}









